<template>
	<view>
		<view>
			<van-card v-for="(item,i) in taskList" :key="i" :desc="item.content" :title="item.title">
				<view slot="footer">
					<van-button size="mini" @click="lookTaskExec(item.id)">查看完成人数</van-button>
					<van-button size="mini" @click="publish(item.id)">{{ item.status== 1? "已发布":"未发布" }}</van-button>
				</view>
			</van-card>
		</view>
		<!-- <button class="cu-btn block bg-blue margin-tb-sm lg dibu" disabled @click="clickRight()">发布任务</button> -->
		<van-goods-action>
			<van-goods-action-button text="发布任务" @click="clickRight()" />
		</van-goods-action>
	</view>
</template>

<script>
	// import uniNavBar from '../../components/uni-nav-bar/uni-nav-bar.vue'
	// import uniList from '../../components/uni-list/uni-list.vue'
	export default {
		components: {
			// uniNavBar,
			// uniList
		},
		data() {
			return {
				taskList: []
			}
		},
		created() {
			this.getData();
		},
		methods: {
			getData() {
				// let teaId = 1
				let teaId = uni.getStorageSync('teaId');
				uni.request({
					url: 'http://localhost:8082/task_admin/task/list?pageNum=1&pageSize=100&teaId=' + teaId,
					success: (res) => {
						console.log(res)
						if (res.data.code == 200) {
							this.taskList = res.data.data
						}
					}
				})
			},
			clickLeft() {
				uni.navigateTo({
					url: '/pages/teacher/index-tea'
				});
			},
			clickRight() {
				uni.navigateTo({
					url: '/pages/teacher/publish-task'
				});
			},
			publish(id) {
				uni.request({
					url: 'http://localhost:8082/task_admin/task/updateStatus?id=' + id,
					method:"PUT",
					success: (res) => {
						this.getData()
					}
				})
			},
			lookTaskExec(taskId) {
				uni.navigateTo({
					url: '/pages/teacher/task-item?taskId=' + taskId
				});
			}
		}
	}
</script>

<style>
	.dibu {
		position: fixed;  
		bottom: 0rpx;
	}
</style>
